home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 172_01 / integ.c < prev    next >
Text File  |  1980-01-01  |  1KB  |  45 lines

  1. /*
  2.   HEADER:              CUG  nnn.nn;
  3.   TITLE:               LEX - A Lexical Analyser Generator
  4.   VERSION:             1.1 for IBM-PC
  5.   DATE:                Jan 30, 1985
  6.   DESCRIPTION:         A Lexical Analyser Generator. From UNIX
  7.   KEYWORDS:            Lexical Analyser Generator YACC C PREP
  8.   SYSTEM:              IBM-PC and Compatiables
  9.   FILENAME:            INTEG.C
  10.   WARNINGS:            This program is not for the casual user. It will
  11.                        be useful primarily to expert developers.
  12.   CRC:                 N/A
  13.   SEE-ALSO:            YACC and PREP
  14.   AUTHORS:             Charles H. Forsyth
  15.                        Scott Guthery 11100 leafwood lane Austin, TX 78750
  16.                        Andrew M. Ward, Jr.  Houston, Texas (Modifications)
  17.   COMPILERS:           LATTICE C
  18.   REFERENCES:          UNIX Systems Manuals -- Lex Manual on distribution disks
  19. */
  20. /*
  21.  * Copyright (c) 1978 Charles H. Forsyth
  22.  */
  23. /*
  24.  * integ -- ascii to long (various bases)
  25.  */
  26. long integ(cp, base)
  27. char *cp;
  28. int base;
  29. {
  30.     int c;
  31.     long n;
  32.  
  33.     n = 0;
  34.     while (c = *cp++) {
  35.         if (c>='A' && c<='Z')
  36.             c += 'a'-'A';
  37.         if (c>='a' && c<='z')
  38.             c = (c-'a')+10+'0';
  39.         if (c < '0' || c > base+'0')
  40.             break;
  41.         n = n*base + c-'0';
  42.     }
  43.     return(n);
  44. }
  45.